<!--renshuai-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="title">
        <el-input
            v-model="queryParams.pdrName"
            placeholder="商家名称"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="status">
        <el-select v-model="queryParams.postStatus" placeholder="邮寄状态" clearable>
          <el-option  v-for="(item,index) in postStatusList" :key="item.value" :label="item.label" :value="item.value"/>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商家" align="center" prop="pdrName"  :show-overflow-tooltip="true"/>
      <el-table-column label="抬头类型" align="center" prop="headType">
        <template slot-scope="scope">
          <span v-for="(item,index) in headTypeList" :key="index" v-if="item.value==scope.row.headType">
            {{item.label}}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="真实姓名" align="center" prop="realName" :show-overflow-tooltip="true"/>
      <el-table-column label="身份证号" align="center" prop="idCardNo" :show-overflow-tooltip="true"/>
      <el-table-column label="企业名称" align="center" prop="companyName" :show-overflow-tooltip="true"/>
      <el-table-column label="税号" align="center" prop="taxNo" :show-overflow-tooltip="true"/>
      <el-table-column label="地址" align="center" prop="address" :show-overflow-tooltip="true"/>
      <el-table-column label="电话号码" align="center" prop="phoneNo" :show-overflow-tooltip="true"/>
      <el-table-column label="开户银行" align="center" prop="bankDpst" :show-overflow-tooltip="true"/>
      <el-table-column label="银行账号" align="center" prop="bankAcct" :show-overflow-tooltip="true"/>
      <el-table-column label="发票金额" align="center" prop="invcAmount" :show-overflow-tooltip="true"/>
      <el-table-column label="接收邮箱" align="center" prop="postEmail"/>
      <el-table-column label="申请时间" align="center" prop="createTime" width="95"/>
      <el-table-column label="邮寄状态" align="center" prop="postStatus" width="90">
        <template slot-scope="scope">
          <dict-tag :options="postStatusList" :value="scope.row.postStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  fixed="right">
        <template slot-scope="scope">
          <el-button
              type="text"
              size="small"
              icon="el-icon-view"
              @click="handleView(scope.row)"
              v-hasPermi="['invc:list:preview']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body center :before-close="handleClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" :class=" !openIsEdit?'noEidt':'' ">
        <el-row>
          <el-col :span="12">
            <el-form-item label="商家">
              <el-input v-model="form.pdrName" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮寄状态">
              <dict-tag :options="postStatusList" :value="form.postStatus"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="抬头类型" prop="headType">
              <el-select v-model="form.headType" placeholder="" :disabled="!openIsEdit">
                <el-option v-for="(item ,index) in headTypeList"
                           :key="index"
                           :label="item.label"
                           :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接收邮箱">
              <el-input v-model="form.postEmail" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="发票金额">
              <el-input v-model="form.invcAmount" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="申请时间">
              <el-input v-model="form.createTime" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row v-if="form.headType=='2'">
          <el-col :span="24">
            <el-form-item label="真实姓名">
              <el-input v-model="form.realName" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="身份证号">
              <el-input v-model="form.idCardNo" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row v-if="form.headType=='1'">
          <el-col :span="24">
            <el-form-item label="企业名称">
              <el-input v-model="form.companyName" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="税号">
              <el-input v-model="form.taxNo" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="地址">
              <el-input v-model="form.address" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="电话号码">
              <el-input v-model="form.phoneNo" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开户银行">
              <el-input v-model="form.bankDpst" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="银行账号">
              <el-input v-model="form.bankAcct" :readonly="!openIsEdit"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="form.postStatus=='0'" @click="handlePost(form.pkId)">已寄出</el-button>
        <el-button @click="handleClose">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getAgByCode, listAgt,updateAgt} from "@/api/cms/agt";
import {invcPost, listPdrPayInvc} from "@/api/fin/pdrpay";
import "@/style/customer.scss";

export default {
  name: "InvcList",
  data() {
    return {
      headTypeList:[
        {
          value:"1",
          label:"企业单位普票"
        },
        {
          value:"2",
          label:"个人/非企业单位普票"
        }
      ],
      postStatusList:[
        {
          raw:{
            listClass:"default",
            cssClass:""
          },
          value:"",
          label:"全部"
        },
        {
          raw:{
            listClass:"primary",
            cssClass:""
          },
          value:"1",
          label:"已寄出"
        },
        {
          raw:{
            listClass:"info",
            cssClass:""
          },
          value:"0",
          label:"未寄出"
        }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否打开编辑
      openIsEdit:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postStatus: undefined,
        pdrName:undefined
      },
      // 表单参数
      form: {
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listPdrPayInvc(this.queryParams).then(response => {
        this.dataList = response.data;
        this.total = Number(response.total);
        this.loading = false;
      });
    },

    /**
     * 详情按钮
     * @param row
     */
    handleView(row){
      this.form = row;
      this.open = true;
      this.openIsEdit=false;
      this.title = "详细信息";
    },

    handlePost(invcId){
      this.$confirm("确认已寄出了吗 ?")
          .then(_ => {
              invcPost(invcId).then(response => {
                this.$modal.msgSuccess("操作成功");
                this.open = false;
                this.getList();
              });
          })
          .catch(_ => {});
    },

    // 取消按钮
    handleClose() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        // noticeId: undefined,
        // noticeTitle: undefined,
        // noticeType: undefined,
        // noticeContent: undefined,
        // status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },


  }
};
</script>
<style lang="scss" scoped>
</style>